
import 'package:flutter/material.dart';
import 'package:flutter_getx/app/base/load_image.dart';
import 'package:flutter_getx/ext/ext.dart';
import 'package:flutter_getx/res/colors/colors.dart';
import 'package:flutter_getx/res/colors/theme_colors.dart';
import 'package:flutter_getx/res/dimens/dimens.dart';
import 'package:flutter_getx/res/strings/strings.dart';
import 'package:flutter_getx/ui/main/model/goods_bean.dart';
import 'package:flutter_getx/widgets/text_gradient_color_widget.dart';

class HomeGoodsItemWidget extends StatelessWidget {

  const HomeGoodsItemWidget(this._item, this.index, {Key? key, this.onTap}) : super(key: key);

  final Object _item;
  final int index;
  final GestureTapCallback? onTap;

  @override
  Widget build(BuildContext context) {
    var item = GoodsBean().parse(_item)!;
    return GestureDetector(
      onTap: onTap,
      child: Column(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          AspectRatio(
            aspectRatio: 173/204,
            child: LoadImage("${item.img}", fit: BoxFit.cover, color: imgColor, colorBlendMode: imgBlendMode,),
          ),
          Text(
            '${item.name}',
            style: subtitle2.copyWith(fontSize: Sp.sp13, height: 1.5,),
            maxLines: 2,
            overflow: TextOverflow.ellipsis,
          ),
          Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              RichText(
                maxLines: 1,
                text: TextSpan(
                  text: unit,
                  style: TextStyle(
                    color: color_FF202C,
                    fontSize: Sp.sp12,
                    fontWeight: FontWeight.w600,
                  ),
                  children: [
                    TextSpan(
                      text: item.price.fmtPrice(),
                      style: TextStyle(fontSize: Sp.sp19),
                    ),
                  ],
                ),
              ),
              SizedBox(height: Dp.dp_4,),
              RichText(
                maxLines: 1,
                text: TextSpan(
                  text: '$unit${item.originalPrice.fmtPrice()}',
                  style: TextStyle(color: color_999, fontSize: Sp.sp12, decoration: TextDecoration.lineThrough,),
                  children: [
                    WidgetSpan(child: SizedBox(width: Dp.dp_4,), style: const TextStyle(decoration: TextDecoration.none)),
                    WidgetSpan(child: TextGradientColorWidget("(${item.discountRate}% off)"), style: const TextStyle(decoration: TextDecoration.none)),
                  ],
                ),
              ),
              SizedBox(height: Dp.dp_6,),
            ],
          )
        ],
      ),
    );
  }
}
